import { initWXConfig } from "@/utils";
import http from "@/utils/http";
// ### 设置昵称
export function setUserNick(params: { nick: string }) {
    return http.post(`/api/bactroban-bus/nick`, params);
}

// ###登录， 返回userid
export async function login() {
    //获取平台 platform
    const openid = localStorage.getItem("openId") || "";
    const res = await fetch(`/api/bactroban-bus/info`, {
        headers: {
            deviceCode: window?.deviceCode,
            openid: openid
        },
    }).then((res) => res.json());
    return Promise.resolve(res.data?.id);
}

// ### 获取用户信息
export function getUserInfo() {
    return http.get(`/api/bactroban-bus/info`).then<{
        id: number;
        create_time: string;
        head_img: string;
        nickname: string;
        platform: string;
        cj_num: number;
        left_cj: number // ?剩余抽奖次数
        score: number;
        openid: string
    }>((res) => {
        const userId = res?.data.id
        userId && localStorage.setItem("userId", userId);
        return res?.data
    });
}